package com.esdut.ciremember;

import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

/**
 * @Company  CiJI
 * @Classname null
 * @Description TODO 系统的登录片段，完成系统登录控制
 * @Author wenXin
 * Date 2021.6.29 08:01
 * Version 1.0
 */
public class LoginFragment extends Fragment {
    private TextView textViewUser,textViewPassword;
    private Button button;
    //所需要的公共构造函数
    public LoginFragment() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // 映射此片段的布局
        return inflater.inflate(R.layout.fragment_login, container, false);
    }
    /**
     * @methodName TODO 登录控制
     * @author wenXin
     * @date 2021/6/30 10:46
     * @return void
     */
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        textViewUser = requireActivity().findViewById(R.id.userText);
        textViewPassword = requireActivity().findViewById(R.id.passwordText);
        button = requireActivity().findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String aUser = textViewUser.getText().toString();
                String aPss = textViewPassword.getText().toString();
                if (aUser.equals("15883556321") || aUser.equals("18383043871") || aUser.equals("18781296044")|| aUser.equals("13982016237")  || aUser.equals("1356514227@qq.com") || aUser.equals("1197199945@qq.com")
                        && aPss.equals("123456")) {
                    NavController navController = Navigation.findNavController(v);
                    navController.navigate(R.id.action_loginFragment_to_wordsFragment);
                    Toast.makeText(requireActivity(),"登陆成功",Toast.LENGTH_SHORT).show();
                } else if (aUser.equals("root")){
                    NavController navController = Navigation.findNavController(v);
                    navController.navigate(R.id.action_loginFragment_to_wordsFragment);
                    Toast.makeText(requireActivity(),"进入管理员模式",Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(requireActivity(),"账号或密码错误，请重新输入",Toast.LENGTH_LONG).show();
                    textViewPassword.setText("");
                }

            }
        });
    }
}